package topic.dp;

public class maxRepeating_1668 {
    public static void main(String[] args) {
        String sequence = "ababc";
        String word = "ab";
        int method = method(sequence, word);
        System.out.println(method);

    }

    //序列dp  从头遍历 截取对比
    public static int method(String sequence, String world) {
        int n = sequence.length();
        int m = world.length();
        int ans = 0;
        int[] f = new int[n + 10];
        for (int i = 1; i <= n; i++) {
            if (i - m < 0) continue;
            if (sequence.substring(i - m, i).equals(world)) {
                f[i] = f[i - m] + 1;
            }
            ans = Math.max(ans, f[i]);
        }
        return ans;
    }
}
